﻿Chenxin.UI.InfoFormGrid=Chenxin.extend(Chenxin.UI.JsonGrid,{
	renderTo:'div_point_list',
	id:'print_grid',
	scope: this,
	exportAble:false,
	hasPage:false,
	title:'业绩申请-点数分配情况',
	autoLoad:false,
	modelId:'RecordId',
	opstatus:true,
	formWidth:600,
	formHeight:400,
	extensible:false,
	hasCheckBox:false,
	checkForm:Chenxin.emptyFn,
	addBtn:'添加分配记录',
	editBtn:'编辑分配记录',
	delBtn:'删除分配记录',
	store:{
		rows:[],
		count:0,
		map:{}
	},
	createTitleTool:function(){					
		return [{
			text: '<span class="x-btn-add"></span>'+this.addBtn,
			scope:this,
			title:this.addBtn,
			handler:function(el){
				this.addRecord();
			}
		},{
			text: '<span class="x-btn-edit"></span>'+this.editBtn,
			scope:this,
			title:this.editBtn,
			handler:function(el){
				this.editRecord();
			}
		},{
			text: '<span class="x-btn-del"></span>'+this.delBtn,
			scope:this,
			title:this.delBtn,
			handler:function(el){
				this.delRecord();
			}
		}];
	},
	addRecord:function(){
		if(!this.opstatus){
			return;
		}
		
		this.showWin();
		this.win.index=-1;
	},
	editRecord:function(){
		if(!this.opstatus){
			return;
		}
		if(!this.currentId){
			alert('请选中一条记录！');
			return;
		}
		this.showWin();
		var data={};
		Chenxin.apply(data,this.store.rows[this.store.map[this.currentId].index]);
		this.win.fitData(data);
		this.win.index=this.store.map[this.currentId].index;
	},
	showWin:function(){
		if(!this.win){
			this.win=new Chenxin.UI.InfoWin({
				actionUrl:this.actionUrl,	
				scope:this,
				id:this.formId,
				title:this.formTitle,
				createForm:this.createFormContent,
				height:this.formHeight,
				width:this.formWidth,
				sureAdd:function(){
					var model=this.getData();
					// if(!model.Point){
						// alert('请填写完必填项！');
						// return;
					// }
					if(this.checkForm){
						if(!this.checkForm.call(this,model)){
							return;
						}
					}
					if(this.index!=-1){//编辑状态
						this.scope.store.rows[this.index]=model;
					}else{
						model.RecordId='abc_'+Math.random()*10000000000;
						model.RecordId=model.RecordId.replace('.','');
												
						this.scope.store.rows.push(model);
						this.scope.store.count++;
					}
					this.scope.reRender();
					this.hide();
				}
			});
		}
		this.win.show();
		this.win.fitData();
	},
	delRecord:function(){
		if(!this.opstatus){
			return;
		}
		
		if(!this.currentId){
			alert('请选中一条记录！');
			return;
		}
		this.store.rows.splice(this.store.map[this.currentId].index,1);
		this.reRender();
	},
	initComponent:function(){
		Chenxin.UI.InfoFormGrid.superclass.initComponent.call(this);
	}
		
});
Chenxin.UI.InfoWin=Chenxin.extend(Chenxin.UI.Win,{	
	id:'x_point_add_win',
	width:580,
	hasFoot:true,
	height:200,
	title:'添加甲方信息',
	createBtn:function(){
		return [{
			text:'保存',
			handler:this.sureAdd
		},{
			text:'关闭',
			handler:this.hide
		}]	
	},
	fitData:function(model){
		model=model||{};
		Chenxin.Fn.setFormValue(this.id,this.comboList,model);
	},
	getData:function(){
		return Chenxin.Fn.getFormJson(this.id);
	},
	initComponent:function(){
		this.content=this.createForm();
		Chenxin.UI.InfoWin.superclass.initComponent.call(this);
	}
});

Chenxin.UI.InfoAGrid=Chenxin.extend(Chenxin.UI.InfoFormGrid,{
	formId:'x_info_a_win',
	formTitle:'添加甲方信息',
	renderTo:'div_info_a_list',
	id:'info_a_grid',
	title: '甲方信息',
	addBtn: '添加甲方信息',
	editBtn: '编辑甲方信息',
	delBtn: '删除甲方信息',
	formWidth:400,
	formHeight:110,
	columns:{
		CustomerName:{
			width:120,
			head:'姓名'
		},
		IDNum:{
			width:200,
			head:'身份证'
		}
	},
	checkForm:function(model){
//		if(!model.IDNum){
//			alert('fasfasd');
//			return false;
//		}
		return true;
	},
	createFormContent:function(){
		var html='<table class="tbl_f jqTabWh" style="margin:30px 0px;">';
		html+='<tr><th style="width:100px;">姓名：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="CustomerName"/></td></tr>';
		html+='<tr><th style="width:100px;">身份证：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="IDNum"></td></tr>';
		html+='</table>';
		
		return html;
	}
});

Chenxin.UI.InfoBGrid = Chenxin.extend(Chenxin.UI.InfoFormGrid, {
    formId: 'x_info_b_win',
    formTitle: '添加乙方信息',
    renderTo: 'div_info_b_list',
    id: 'info_b_grid',
    title: '乙方信息',
    addBtn: '添加乙方信息',
    editBtn: '编辑乙方信息',
    delBtn: '删除乙方信息',
    formWidth: 380,
    formHeight: 250,
    columns: {
        BOwner: {
            width: 40,
            head: '主贷人',
            renderer: function(val, c, row) {
                val = val + '';
                if (val == 'true')
                    return "<input type=radio name='BOwner' checked disabled='disabled' />";
                else
                    return "<input type=radio name='BOwner' disabled='disabled'/>";
            }
        },
        CustomerName: {
            width: 65,
            head: '姓名'
        },
        IDNum: {
            width: 150,
            head: '身份证'
        },
        GJJNum: {
            width: 100,
            head: '公积金账号'
        },
        SpousesName: {
            width: 65,
            head: '配偶姓名'
        },
        SpousesIDNum: {
            width: 150,
            head: '身份证号'
        },
        SpousesGJJNum: {
            width: 100,
            head: '公积金账号'
        }
    },
    checkForm: function(model) {
        //        if (!model.CustomerName) {
        //            alert('fasfasd');
        //            return false;
        //        }
        return true;
    },
    createFormContent: function() {
        var html = '<table class="tbl_f jqTabWh" style="margin:30px 0px;">';
        html += '<tr><th style="width:100px;">主贷人：</th><td><input type="radio" name="BOwner" value="true">是<input type="radio" name="BOwner" value="false">否</td></tr>';
        html += '<tr><th style="width:100px;">姓名：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="CustomerName"/></td></tr>';
        html += '<tr><th style="width:100px;">身份证：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="IDNum"></td></tr>';
        html += '<tr><th style="width:100px;">公积金账号：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="GJJNum"></td></tr>';
        html += '<tr><th style="width:100px;">配偶姓名：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="SpousesName"></td></tr>';
        html += '<tr><th style="width:100px;">身份证号：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="SpousesIDNum"></td></tr>';
        html += '<tr><th style="width:100px;">公积金账号：</th><td><input type="text" style="width: 200px;" class="inputbox_n fl" name="SpousesGJJNum"></td></tr>';
        html += '</table>';

        return html;
    }
});
